class AsyncParallelHook { // 钩子是同步的
  constructor(args) { // agrs => ['name']
    this.tasks = []
  }
  tapPromise(name, task) {
    this.tasks.push(task)
  }
  promise(...args) {
    let tasks = this.tasks.map(task =>　{
      task(...args)
    })
    return Promise.all(tasks)
  }
}

let hook = new AsyncParallelHook(['name'])
hook.tapPromise('react', function(name) {
  return new Promise((resolve, reject) =>　{
    setTimeout(()=> {
      console.log('react', name)
      resolve()
    }, 1000)
  })
})
hook.tapPromise('node', function(name) {
  return new Promise((resolve, reject) =>　{
    setTimeout(()=> {
      console.log('node', name)
      resolve()
    }, 1000)
  })
})
hook.tapPromise('webpack', function(name) {
  return new Promise((resolve, reject) =>　{
    setTimeout(()=> {
      console.log('webpack', name)
      resolve()
    }, 1000)
  })
})
// hook.call('hl2')
hook.promise(['hl1', 'hl2'], ()=> {
  console.log('end')
})

//  AsyncParallelBailHook() 带保险的异步并发的钩子
